<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	cfc('core')->checklogin();
	$basic=$this->plugin_setting('basic');
	$return['member']=cfc('core')->get_member($_SESSION['uid']);
	$p_group=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isrecommand'=>'1','isshow'=>'1','parentid'=>'0'),'','paixu asc');
	//子分类
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$params['saletype likes']=array('1');
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','title','image','price','total','active_plugin','active_id');
	if($p_group){
		$i=0;
		foreach($p_group as &$item){
			$item['c_group']=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>'1','isrecommand'=>'1','parentid'=>$item['id']),'','paixu asc');
			$item['goodslist']=pdo_getslice('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'saletype likes'=>array('1'),'pcate'=>$item['id']),array($pindex,$psize),$total,$fields,'','paixu desc');
			$item['goodsnew']=pdo_getslice('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'saletype likes'=>array('2'),'pcate'=>$item['id']),array($pindex,$psize),$total,$fields,'','paixu desc');
			$item['style']=style($item['id']);
			$i=$i+1;
			$item['i']=$i;
			if($item['c_group']){
				foreach($item['c_group'] as &$row){
					$params['ccate']=$row['id'];
					$row['goods']=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,$fields,'','paixu desc');
				}
			}
		}
	}
	$return['p_group']=$p_group;
	$return['cartnums']= pdo_getsum('jy_weishop_member_cart',array('mid'=> $_SESSION['uid'], 'uniacid' => $_SESSION['uniacid']),'total');
	$pindex = max(1, intval($post['page']));
	$psize = 10;
	$total='';
	$sale_luck=plugin('jy_weishop')->plugin_setting('sale_luck');
	if($sale_luck['isopen']==1){
			if(isset($_RQ['luckkey'])){
				$return['sale_luck']=model('jy_weishop/activity/sales')->jieluck($_RQ['luckkey']);
			}else{
				$return['sale_luck']=model('jy_weishop/activity/sales')->getluck();
			}
	}
	if(!$return['sale_luck']){
			$isshow_sale_offer=$this->session('isshow_sale_offer');
			if(!$isshow_sale_offer){
				$return['sale_offer']=model('jy_weishop/activity/sales')->getoffer();
			}
			if(!$return['sale_offer']){
				$return['orderlist']=pdo_getslice('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'deleted'=>0,'status'=>0),array($pindex,$psize),$total,'','','createtime desc');
				foreach($return['orderlist'] as &$ov){
					$ordergoods=pdo_get('jy_weishop_order_goods',array('orderid'=>$ov['id'],'uniacid'=>$_SESSION['uniacid']),array('goodsid','optionid','price','total','goodssn','productsn'));
					$goodsinfo=pdo_get('jy_weishop_goods',array('id'=>$ordergoods['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','image','title','merchid'));
					$ov['goods']=array_merge($ordergoods,$goodsinfo);
					$ov['createtime']=date('Y/m/d H:i:s',$ov['createtime']);
					$ov['total']=pdo_getsum('jy_weishop_order_goods',array('orderid'=>$ov['id'],'uniacid'=>$_SESSION['uniacid']),'total');
				}
				$return['allprice']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'deleted'=>0,'status'=>0),'price');
				if(empty($return['orderlist'])){
					$return['coupon_wait']=model('jy_weishop/task')->pop_coupon_wait();
					$return['coupon_wait']=$return['coupon_wait']?$return['coupon_wait'][0]:false;
					if(!$return['coupon_wait']){
						$return['coupon_hd']=model('jy_weishop/task')->pop_coupon_hd();
						if(!$return['coupon_hd']){
							$return['game_wait']=model('jy_weishop/task')->pop_game();
						}
					}
				}
			}else{
					$this->session('isshow_sale_offer',1);
			}
	}
	if($return['sale_luck']){
		$sharelink='jy_weishop/activity//fromuser='.$_SESSION['uid'].'&luckkey='.$return['sale_luck']['luckkey'];
		if($sale_luck['share_title']){
			$sale_luck['share_title']=str_replace('[lucktitle]',$return['sale_luck']['title'],$sale_luck['share_title']);
		}
		if($sale_luck['share_desc']){
			$sale_luck['share_desc']=str_replace('[lucktitle]',$return['sale_luck']['title'],$sale_luck['share_desc']);
		}
		$return['sharedata']=array(
			'title'=>$sale_luck['share_title']?$sale_luck['share_title']:'我今日运势《'.$return['sale_luck']['title'].'》，快来借势吧,好运势享大折扣!',
			'desc'=>$sale_luck['share_desc']?$sale_luck['share_desc']:'拥有好运势，不仅仅拥有好心情，更能享受好的购物折扣哦！',
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>$sale_luck['share_image']?tomedia($sale_luck['share_image']):tomedia('../addons/jy_weishop/resource/images/sales/luck_share_image.jpg')
		);
	}else{
		$sharelink='jy_weishop/activity//fromuser='.$_SESSION['uid'];
		$return['sharedata']=array(
			'title'=>$return['shopset']['title']?$return['shopset']['title']:'活动页-在线商城',
			'desc'=>$return['shopset']['desc']?$return['shopset']['desc']:'在线商城，一个属于自己的商城！',
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>ATTACHMENT_URL.$return['shopset']['logo']
		);
	}
	$return['setting']['bankuai2']=$return['shopset']['bankuai2'];
	$return['list']=array();
	$return['pcd']=array();
	$return['params']['pid']=intval($_RQ['pid']);
	if(intval($_RQ['pid'])){
		$return['isgroup']=true;
	}
	if($_RQ['order']){
		$return['params']['order']=$_RQ['order'];
	}
	if($_RQ['sale_libaoid']){
		$return['params']['sale_libaoid']=$_RQ['sale_libaoid'];
	}
	set_html('title',$return['shopset']['title']?$return['shopset']['title']:'商城活动');
	exi($return);
}
function style($id)
{
	switch ($id%7) {	
		case 0: return "style-brown";
		case 1: return 'style-red';
		case 2: return "style-pink";
		case 3: return "style-orange";
		case 4: return "style-green";
		case 5: return "style-blue";
		case 6: return "style-purple";
		case 7: return "style-brown";
		default: }
}
?>